//
// Created by tys on 2017/10/25.
//

#ifndef MYPLAYER_VIDEOMEDIA_H
#define MYPLAYER_VIDEOMEDIA_H


#include <queue>
#include <jni.h>
#include "MultiMedia.h"
#include "AudioMedia.h"

extern "C" {
#include <libswscale/swscale.h>
#include <libavutil/pixdesc.h>
#include <libavutil/imgutils.h>
#include <libavutil/time.h>
};

class VideoMedia : public MultiMedia {


public:

    VideoMedia(void (*native_window_play)(AVFrame *, VideoMedia *));

    virtual ~VideoMedia();

    pthread_cond_t cond;

    pthread_mutex_t mutex;

    std::queue<AVPacket *> queue;

    int dst_pic_w, dst_pic_h;

    /**native window 播放fram*/
    void (*play_call_back)(AVFrame *frame, VideoMedia *video);

    SwsContext *sws_ctx;

    /**是否在播放，是否消费packet*/
    bool isPlay;

    AudioMedia* audio;

    void setAudio(AudioMedia *audio);

    void put(AVPacket *pPacket);

    void get(AVPacket **packet);

    void setIsPlay(bool isPlay);

    void play();

    pthread_t thread_t_video;

    int initSwsCtx();

    //时间纠正
    double synchronize_display_time(AVFrame *pFrame, double d);
};


#endif //MYPLAYER_VIDEOMEDIA_H
